home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume4 / rcsit2 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  21.8 KB

  1. Subject: new version of rcsit(1) - prepare files for RCS
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 41
  6. Submitted by: usc-oberon!mcooper (Mike Cooper)
  7.  
  8. #!/bin/sh
  9. # This is a shell archive, meaning:
  10. # 1. Remove everything above the #!/bin/sh line.
  11. # 2. Save the resulting text in a file.
  12. # 3. Execute the file with /bin/sh (not csh) to create the files:
  13. #    README
  14. #    Makefile
  15. #    rcsit.1
  16. #    rcsit.c
  17. #    _.header.c
  18. # This archive created: Thu Mar 27 14:27:28 1986
  19. # By:    Michael A. Cooper (University Computing Services, U.S.C.)
  20. export PATH; PATH=/bin:$PATH
  21. echo shar: extracting "'README'" '(974 characters)'
  22. if test -f 'README'
  23. then
  24.     echo shar: over-writing existing file "'README'"
  25. fi
  26. cat << \SHAR_EOF > 'README'
  27. Enclosed is a shar archive of a program called rcsit(1) that I
  28. submitted to mod.sources several months ago (November '85???).
  29. It has gone through some enhancments and bug fixes (see rcsit.c
  30. for specifics).
  31.  
  32. The program itself, does things like add rcs headers (for log
  33. tracking, version tracking, etc.) and (optionally) run rcs
  34. commands (like ci(1)) on the specified files.
  35.  
  36. Please mail me any bugs/comments that you run across.
  37.  
  38.  
  39.             Thanks,
  40.             Mike Cooper
  41.  
  42. +-----------------------------------------------------------------------------+
  43. | Michael Cooper            UUCP: ...!{uscvax, sdcrdcf, engvax,          |
  44. | University Computing Services          scgvaxd, smeagol}!usc-oberon!mcooper |
  45. | University of Southern Cal.     BITNET: mcooper@uscvaxq, mcooper@jaxom      |
  46. | Los Angeles, Ca.   90089-0251     ARPA: mcooper@usc-oberon.arpa,          |
  47. | (213) 743-3462                mcooper@usc-eclc.arpa            |
  48. +-----------------------------------------------------------------------------+
  49. SHAR_EOF
  50. echo shar: extracting "'Makefile'" '(438 characters)'
  51. if test -f 'Makefile'
  52. then
  53.     echo shar: over-writing existing file "'Makefile'"
  54. fi
  55. cat << \SHAR_EOF > 'Makefile'
  56. #
  57. # $Header: Makefile,v 1.1 85/09/19 13:24:27 mcooper Exp $
  58. #
  59. # $Log:    Makefile,v $
  60. # Revision 1.1  85/09/19  13:24:27  mcooper
  61. # Initial revision
  62. #
  63. #
  64. # Makefile for rcsit.c
  65. #
  66. BIN = /usr/unsupp
  67. MAN = /usr/man/manu/man1
  68.  
  69. rcsit: rcsit.c
  70.     cc -O -s -o rcsit rcsit.c
  71.  
  72. dbx: rcsit.c
  73.     cc -g rcsit.c
  74.  
  75. debug: rcsit.c
  76.     cc -g -DDEBUG rcsit.c
  77.  
  78. man: rcsit.1
  79.     nroff -man rcsit.1 > rcsit.man
  80.  
  81. install: rcsit rcsit.1
  82.     mv rcsit $(BIN)
  83.     cp rcsit.1 $(MAN)
  84. SHAR_EOF
  85. echo shar: extracting "'rcsit.1'" '(5030 characters)'
  86. if test -f 'rcsit.1'
  87. then
  88.     echo shar: over-writing existing file "'rcsit.1'"
  89. fi
  90. cat << \SHAR_EOF > 'rcsit.1'
  91. ...
  92. ... $Header: rcsit.1,v 1.12 86/03/27 14:05:08 mcooper Exp $
  93. ... 
  94. ... $Log:    rcsit.1,v $
  95. ... Revision 1.12  86/03/27  14:05:08  mcooper
  96. ... fixed syntax errors.
  97. ... 
  98. ... Revision 1.11  86/03/12  14:11:05  mcooper
  99. ... *** empty log message ***
  100. ... 
  101. ... Revision 1.10  86/02/03  14:23:07  mcooper
  102. ... Added description of ``Pascal'' types.
  103. ... Cleaned up table displays.
  104. ... Deleted most of the log messages.
  105. ... 
  106. ... Revision 1.9  85/12/19  14:22:41  mcooper
  107. ... Added updates from Joe Chapman for TeX.
  108. ... 
  109. ... Revision 1.8  85/12/16  17:33:33  mcooper
  110. ... Changed .template.* --> .header.*
  111. ... More appropriate name.
  112. ... 
  113. ...
  114. .TH RCSIT 1l
  115. .SH NAME
  116. rcsit \- A program to prepare files for RCS
  117. .SH SYNOPSIS
  118. rcsit
  119. [
  120. .B \-chfsmMxp
  121. ] [
  122. .B \-qad
  123. ] [
  124. \-I\fIflags\fR
  125. ] [
  126. \-R\fIflags\fR
  127. ] [
  128. \-H\fIdirectory\fR
  129. ] [
  130. \-F\fIheader-file\fR
  131. ]
  132. .B file
  133. [
  134. .B file1 file2 ...
  135. ]
  136. .SH DESCRIPTION
  137. .I Rcsit
  138. is a semi-intelligent program to prepare files for 
  139. .I rcs(1).
  140. This
  141. involves putting the correct type of headings at the top of the file so
  142. that 
  143. .I rcs(1)
  144. will update a header and log changes in the file.
  145. .PP 
  146. By default, 
  147. .I rcsit
  148. will use default headers ``hard-wired'' into itself for each different file
  149. type that it ``knows'' about.  (See below for list of known file types).
  150. .PP
  151. If the \-H\fIdirectory\fR option is specified, then
  152. .I rcsit
  153. will use ``.header.suffix'' files
  154. (where ``suffix'' is a suffix that 
  155. .I rcsit
  156. ``knows'' about)
  157. found in 
  158. .I directory.
  159. If a directory name is not specified on the command line, then
  160. the environment variable TEMPLATES is used.
  161. If TEMPLATES is not set, then the environment varialble, HOME is tried.
  162. .LP
  163. The following template files are recognized:
  164. .sp
  165. .DS
  166.  Template Name             File Type
  167.  -------------------------------------------
  168.  .header.c                 Standard C
  169.  .header.h                 C Include
  170.  .header.f                 Fortran
  171.  .header.sh                Shell Script
  172.  .header.make              Makefile
  173.  .header.man               Manual
  174.  .header.p                 Pascal
  175.  .header.tex               TeX
  176. .DE
  177. .PP
  178. .I Rcsit
  179. is ``semi-intelligent'' in that it can guess the type of headers to put in
  180. the file by the type of file (C program, C include, makefile, shell script,
  181. or manual).
  182. It determines the file type by looking at the name of the file.
  183. If the name of the file is ``Makefile'' or ``makefile'', then the
  184. file type is taken to be for 
  185. .I make(1).
  186. The suffix after the last ``.'' in the file name is then used.
  187. The following table shows the suffixes that 
  188. .I rcsit
  189. knows about:
  190. .sp
  191. .DS
  192.  Suffix         File Type
  193.  ----------------------------------------
  194.  c              C Program
  195.  h              C Include
  196.  f              Fortran
  197.  mk             \fIMake(1)\fR file
  198.  sh             Shell Script
  199.  csh            Shell Script
  200.  [1-9]          Manual (digits 1 - 9)
  201.  p              Pascal
  202.  tex            TeX
  203. .DE
  204. .PP
  205. If the environment variable ``RCSDIR'' is present, then 
  206. .I rcsit
  207. will attempt to make a symbolic link from it to ``RCS'' in
  208. the current directory if the \-\fII\fR option is used and
  209. there is no directory called ``RCS'' already, in the current
  210. directory.  
  211. If the \-\fII\fR option is used and ``RCSDIR'' is not specified
  212. in the environment, then a normal directory called ``RCS'' will be
  213. created.
  214. This feature can be overrided with the \-\fId\fR option.
  215. .SH OPTIONS
  216. .TP 10
  217. .B "c"
  218. Force file type to be ``Standard C''.
  219. .TP 10
  220. .B "h"
  221. Force file type to be ``C Include''.
  222. .TP 10
  223. .B "f"
  224. Force file type to be ``Fortran''.
  225. .TP 10
  226. .B "M"
  227. Force file type to be ``Manual''.
  228. Note: If you also specify the ``I\fIflags\fR'' option,
  229. .I rcsit
  230. will run 
  231. .I rcs(1)
  232. to tell rcs what kind of comment string to use for the manual file.
  233. .TP 10
  234. .B "s"
  235. Force file type to be ``Shell Script''.
  236. .TP 10
  237. .B "m"
  238. Force file type to be ``Makefile''.  Note that this does the same thing as
  239. the -s option does.  It just prints a different message.
  240. .TP 10
  241. .B "p"
  242. Force file type to be ``Pascal''.
  243. .TP 10
  244. .B "x"
  245. Force file type to be ``TeX''.
  246. .TP 10
  247. .B "F\fIheader-file\fR"
  248. Use
  249. .I header-file
  250. as the header file.  (i.e. This file
  251. is prepended to each of the files to be processed.)
  252. .TP 10
  253. .B "t"
  254. Do not use any Template files for the headers.
  255. .TP 10
  256. .B "q"
  257. Be quiet.  Don't print out what is going on.  Only error messages are
  258. printed.
  259. .TP 10
  260. .B "d"
  261. Do not attempt to make the directory ``RCS''.
  262. See above for more info.
  263. .TP 10
  264. .B "a"
  265. Turn off auto guessing of file type.
  266. .TP 10
  267. .B "I\fIflags\fR"
  268. Check In file.
  269. Run RCS's 
  270. .I ci(1)
  271. on the file with ``flags'' being passed onto 
  272. .I ci(1) 
  273. as the command line arguments.
  274. .TP 10
  275. .B "R\fIflags\fR"
  276. Run 
  277. .I rcs(1)
  278. with ``flags'' as the command line arguments.
  279. .SH FILES
  280. /tmp/rcsit*    - temporary buffer
  281. .br
  282. ~/.header.*   - template files to use as the header.
  283. .br
  284. .SH AUTHOR
  285. Michael Cooper (mcooper@usc-oberon.ARPA)
  286. .SH SEE ALSO
  287. ci(1), make(1), rcs(1)
  288. .SH DIAGNOSTICS
  289. Complains about the usual stuff.  (i.e. - the specified file doesn't exist,
  290. or it can't read it...just things like that.)
  291. .SH BUGS
  292. Acts oddly in the presence of beautiful women.
  293. SHAR_EOF
  294. echo shar: extracting "'rcsit.c'" '(13842 characters)'
  295. if test -f 'rcsit.c'
  296. then
  297.     echo shar: over-writing existing file "'rcsit.c'"
  298. fi
  299. cat << \SHAR_EOF > 'rcsit.c'
  300. #ifndef lint
  301. static char *RCSid = "$Header: rcsit.c,v 1.26 86/03/27 14:16:01 mcooper Exp $";
  302. #endif
  303.  
  304. /*
  305.  *---------------------------------------------------------
  306.  * $Source: /w/mcooper/src/rcsit/RCS/rcsit.c,v $
  307.  * $Revision: 1.26 $
  308.  * $Date: 86/03/27 14:16:01 $
  309.  * $State: Exp $
  310.  * $Author: mcooper $
  311.  * $Locker: mcooper $
  312.  *---------------------------------------------------------
  313.  * Michael Cooper (mcooper@usc-oberon.arpa)
  314.  * University Computing Services,
  315.  * University of Southern California,
  316.  * Los Angeles, California,   90089-0251
  317.  * (213) 743-3462
  318.  *---------------------------------------------------------
  319.  *
  320.  * $Log:    rcsit.c,v $
  321.  * Revision 1.26  86/03/27  14:16:01  mcooper
  322.  * Added usage() message.
  323.  * Moved $Header$ into object for ident.
  324.  * 
  325.  * Revision 1.25  86/02/26  15:03:45  mcooper
  326.  * Added -Fheader_file option.
  327.  * 
  328.  * Revision 1.24  86/02/06  10:58:59  mcooper
  329.  * Fixed default error message.
  330.  * 
  331.  * Revision 1.23  86/02/03  14:17:07  mcooper
  332.  * Added the type ``Pascal''.
  333.  * Also deleted log messages up until 1.17
  334.  * (first mod.sources release).
  335.  * 
  336.  * Revision 1.22  85/12/19  14:24:35  mcooper
  337.  * Added more patches from Joe Chapman (joe@cca-unix.ARPA)
  338.  * for TeX support.  Also used his suggestion for
  339.  * checking to see if only one of the file spec. flags
  340.  * is set.
  341.  * 
  342.  * Revision 1.21  85/12/18  11:05:50  mcooper
  343.  * Added "#ifndef lint" to the default header for .c 
  344.  * files.  This keeps lint quite about the:
  345.  * 
  346.  *     static char RCSid
  347.  * 
  348.  * Revision 1.20  85/12/18  10:21:24  mcooper
  349.  * Added patches from Joe Chapman (joe@cca-unix.ARPA)
  350.  * to keep from dereferencing NULL on the 68K.
  351.  * 
  352.  * Revision 1.19  85/12/16  17:34:11  mcooper
  353.  * Changed .header.* --> .header.*
  354.  * More appropriate name.
  355.  * 
  356.  * Revision 1.18  85/11/26  17:03:32  mcooper
  357.  * Change message telling of what header was added.
  358.  * 
  359.  */
  360.  
  361. /*
  362.  * rcsit --     Prepare files for RCS.  rcsit puts the correct headings
  363.  *        at the top of files to prepare them for RCS headings
  364.  *        and log tracking.
  365.  *
  366.  * Michael Cooper    (mcooper@usc-oberon.arpa)
  367.  * University Computing Services, USC
  368.  *
  369.  * 9-16-85
  370.  */
  371.  
  372. #include <stdio.h>
  373. #include <ctype.h>
  374. #include <sys/file.h>
  375.  
  376. #ifdef NULL
  377. #undef NULL
  378. #endif
  379. #define NULL        '\0'
  380. #define LENGTH        132        /* length of line */
  381. #define TRUE        1
  382. #define FALSE        0
  383. #define USAGE "[ -chfsmMxp ] [ -qad ] [ -I{flags} ] [ -R{flags} ] \
  384. \n\t\t[ -H{directory} ] [ -F header_file ] file [ file1 file2 ... ]\n"
  385.  
  386. #ifdef DEBUG
  387.  int debugon = TRUE;
  388. #else
  389.  int debugon = FALSE;
  390. #endif
  391.  
  392. static char     *progname;        /* program name */
  393. static char     *rcsdir;
  394.  
  395. /*
  396.  * Messages to be printed for the user.
  397.  */
  398. static char    *msg_name;        
  399. static char     *m_stdc = "Standard C",
  400.         *m_include = "C Include",
  401.         *m_fortran = "Fortran",
  402.         *m_pascal = "Pascal",
  403.         *m_make    = "Makefile",
  404.         *m_shell = "Shell Script",
  405.         *m_manual = "Manual",
  406.         *m_tex = "TeX";
  407.  
  408. /*
  409.  * The default headers to put at the beginning of the file(s).
  410.  * Notice that the words Header and Log do not appear here
  411.  * because RCS will put in the keyword substitutions when rcsit.c
  412.  * is co'ed.
  413.  */
  414. static char    *header;
  415. static char    *h_stdc = 
  416. "#ifndef lint\nstatic char *RCSid = \"$%s$\";\n#endif\n\n/*\n * $%s$\n */\n\n";
  417. static char    *h_include = 
  418.     "/*\n * $%s$\n *\n * $%s$\n */\n\n";
  419. static char    *h_make =
  420.     "#\n# $%s$\n#\n# $%s$\n#\n";
  421. static char     *h_manual =
  422.     "...\n... $%s$\n... \n... $%s$\n...\n";
  423. static char     *h_fortran =
  424.     "c\nc $%s$\nc\nc $%s$\nc\n";
  425. static char    *h_tex =
  426.     "%% $%s$\n%%\n%% $%s$\n%%\n";
  427. static char    *h_pascal = 
  428.     "(*\n * $%s$\n *\n * $%s$\n *)\n\n";
  429.  
  430. /*
  431.  * Header file names
  432.  */
  433. static char    *header_c     = ".header.c";        /* .c header */
  434. static char     *header_h     = ".header.h";        /* .h header */
  435. static char     *header_f     = ".header.f";        /* .f header */
  436. static char     *header_p     = ".header.p";        /* .p header */
  437. static char     *header_man     = ".header.man";    /* man header */
  438. static char    *header_make    = ".header.make";    /* make header */
  439. static char    *header_sh    = ".header.sh";        /* sh script header */
  440. static char    *header_tex    = ".header.tex";    /* TeX header */
  441. static char    *tpath;                    /* path to header */
  442. static char    tfile[BUFSIZ];                /* header file */
  443. static char    tbuf[BUFSIZ];                /* current tfile */
  444.  
  445. /*
  446.  * Command line flags
  447.  */
  448. int    Iflag    = FALSE;            /* run ci(1) */
  449. int    rcsflag = FALSE;            /* run rcs(1) */
  450. int    aflag    = TRUE;                /* do auto guess */
  451. int    dflag    = TRUE;                /* creat RCS dir. */
  452. int    qflag    = FALSE;            /* be quiet! */
  453. int     cflag    = FALSE;            /* std c file */
  454. int    fflag    = FALSE;            /* fortran file */
  455. int    pflag    = FALSE;            /* pascal file */
  456. int    hflag    = FALSE;            /* include file */
  457. int    sflag    = FALSE;            /* shell script */
  458. int     mflag    = FALSE;            /* Makefile */
  459. int    Mflag    = FALSE;            /* manual */
  460. int    Hflag    = FALSE;            /* header flag */
  461. int    Fflag    = FALSE;            /* header file flag */
  462. int    xflag    = FALSE;            /* TeX flag */
  463.  
  464. main(argc, argv)
  465. int    argc;
  466. char     *argv[];
  467. {
  468.     int x;
  469.     char    tmp[LENGTH];
  470.     char    *file;
  471.     char    *flags;
  472.     char     *tmpfile = "/tmp/rcsitXXXXXX";
  473.     char     *mktemp();
  474.     char    *gettmp();
  475.     char    *getenv();
  476.     FILE     *fd, 
  477.         *fdtmp,
  478.         *fopen();
  479.  
  480.     progname = *argv;
  481.     for (x = 1; x < argc; x++) {
  482.         if (argv[x][0] != '-')
  483.             break;
  484.         switch (argv[x][1]) {
  485.             case 'a':
  486.                 aflag = FALSE;
  487.                 break;
  488.             case 'q':
  489.                 qflag = TRUE;
  490.                 break;
  491.             case 'd':
  492.                 dflag = FALSE;
  493.                 break;
  494.             case 'f':
  495.                 fflag = TRUE;
  496.                 break;
  497.             case 'h':
  498.                 hflag = TRUE;
  499.                 break;
  500.             case 's':
  501.                 sflag = TRUE;    
  502.                 break;
  503.             case 'm':
  504.                 mflag = TRUE;
  505.                 break;
  506.             case 'M':
  507.                 Mflag = TRUE;
  508.                 break;
  509.             case 'i':
  510.             case 'I':
  511.                 Iflag = TRUE;
  512.                 flags = &argv[x][2];
  513.                 break;
  514.             case 'r':
  515.             case 'R':
  516.                 rcsflag = TRUE;
  517.                 flags = &argv[x][2];
  518.                 break;
  519.             case 'F':
  520.                 Fflag = TRUE;
  521.                 strcpy(tfile, &argv[x][2]);
  522.                 msg_name = &argv[x][2];
  523.                 break;
  524.             case 'H':
  525.                 Hflag = TRUE;
  526.                 tpath = &argv[x][2];
  527.                 break;
  528.             case 'c':
  529.                 cflag = TRUE;
  530.                 break;
  531.             case 'x':
  532.                 xflag = TRUE;
  533.                 break;
  534.             case 'p':
  535.                 pflag = TRUE;
  536.                 break;
  537.             default:
  538.                 usage();
  539.         }
  540.     }
  541.     argc -= (x - 1);
  542.     argv += (x - 1);
  543.  
  544.     if(hflag + mflag + Mflag + cflag + sflag + fflag + xflag + pflag > 1)
  545.         fatal("Only ONE of -c,-f,-m,-M,-h,-s,-p,-x may be specified.");
  546.     if(Iflag && rcsflag) 
  547.         fatal("Only ONE of ``-i'' and ``-r'' may be specified.");
  548.  
  549.     if(cflag || hflag || mflag || Mflag || fflag || sflag || xflag || pflag)
  550.         aflag = FALSE;
  551.  
  552.     if((rcsdir = getenv("RCSDIR")) == NULL)
  553.         rcsdir = "RCS";
  554.     if(Iflag && dflag)
  555.         checkdir();    /* Make RCS directory for ci */
  556.  
  557.     if((tpath == NULL || *tpath == NULL) && 
  558.         ((tpath = getenv("TEMPLATE")) == NULL))
  559.         if((tpath = getenv("HOME")) == NULL)
  560.             fatal(
  561.               "Cannot find environment variable HOME or TEMPLATE");
  562.  
  563.     /*
  564.      * make tmp file once.
  565.      */
  566.     mktemp(tmpfile);
  567.  
  568.     while (--argc) {    /* Main loop */
  569.         file = *++argv;
  570.         debug(sprintf(tmp, "...file (*++argv) = %s...", file));
  571.  
  572.         if(access(file, 4) != 0)
  573.             fatal(
  574.         "Cannot access %s.  No read permission OR file does not exist.",
  575.                 file);
  576.         if((fdtmp = fopen(tmpfile, "w")) == NULL) {
  577.             fatal("Cannot open tmpfile (%s).", tmpfile);
  578.         }
  579.  
  580.         if(!Fflag)
  581.             if(aflag)
  582.                 auto_guess(file); /* try and guess file type */
  583.             else
  584.                 set_flags();      /* check and set flags */
  585.  
  586.         if(Hflag && !Fflag) {
  587.             /*
  588.              * first get names of headers, then create
  589.              * path name to it.
  590.              */
  591.             get_temp();
  592.             sprintf(tfile, "%s/%s", tpath, tbuf);
  593.         }
  594.         if(access(tfile, 0) == 0 && (Hflag || Fflag)) {
  595.             if(!qflag || debugon)
  596.                 printf("Adding %s header file to %s...",
  597.                     msg_name, file);
  598.             copy(tfile, tmpfile, "w");
  599.             copy(file, tmpfile, "a");
  600.         } else {
  601.             if(!qflag || debugon)
  602.                 printf(
  603.                 "Adding default header (%s format) to %s...",
  604.                     msg_name, file);
  605.             /*
  606.              * put the Keywords into header string
  607.              */
  608.             sprintf(tmp, header, "Header", "Log");
  609.             fputs(tmp, fdtmp);
  610.             /*
  611.              * fclose'em, just in case.
  612.              */
  613.             fclose(fdtmp);
  614.             copy(file, tmpfile, "a");
  615.         }
  616.         unlink(file);
  617.         copy(tmpfile, file, "w");
  618.         unlink(tmpfile);
  619.  
  620.         if(!qflag || debugon)
  621.             printf("done.\n");
  622.  
  623.         if(Iflag){
  624.             rcs("ci", file, flags);
  625.             if(Mflag){    /* kludge to tell rcs about manuals */
  626.                 rcs("rcs", file, "c'... '");
  627.                 /*
  628.                  * kludge part 2 - if the user tried a ci
  629.                  * with a -l option, then the header is
  630.                  * messed up in the currently checked out
  631.                  * man file.  So we have to co the file to 
  632.                  * clean up the header.  Plus we use the
  633.                  * -l option of co to insure file locking.
  634.                  */
  635.                 if(checkfor("l", flags)){
  636.                     unlink(file);
  637.                     rcs("co", file, "l");
  638.                 }
  639.             }
  640.         }
  641.         if(rcsflag)
  642.             rcs("rcs", file, flags);
  643.     }
  644. }
  645.  
  646. /*
  647.  * debug - print (useless) debugging info.
  648.  */
  649.  
  650. debug(msg)
  651. char *msg;
  652. {
  653. #ifdef DEBUG
  654.     fprintf(stderr, msg);
  655.     putchar ('\n');
  656. #endif
  657. }
  658.  
  659. /*
  660.  * auto_guess - try and be intelligent and guess type of file
  661.  *        by looking at the suffix or the whole name
  662.  *        in the case of a makefile.
  663.  */
  664.  
  665. auto_guess(file)
  666. char    *file;
  667. {
  668.     char *suffix;
  669.     char *rindex();
  670.  
  671.     suffix = rindex(file, '.')+1;
  672.     if((strcmp(file, "makefile") == 0) || (strcmp(file, "Makefile") == 0) ||
  673.         (strcmp(suffix, "mk") == 0)) {    /* sys V std suffix */
  674.         mflag = TRUE;
  675.         sflag = FALSE;
  676.         cflag = FALSE;
  677.         hflag = FALSE;
  678.         Mflag = FALSE;
  679.         fflag = FALSE;
  680.         xflag = FALSE;
  681.         pflag = FALSE;
  682.     }
  683.     if((strcmp(suffix, "sh") == 0) || (strcmp(suffix, "csh") == 0)) {
  684.         sflag = TRUE;
  685.         cflag = FALSE;
  686.         hflag = FALSE;
  687.         mflag = FALSE;
  688.         Mflag = FALSE;
  689.         fflag = FALSE;
  690.         xflag = FALSE;
  691.         pflag = FALSE;
  692.     }
  693.     if(strcmp(suffix, "tex") == 0) {
  694.         xflag = TRUE;
  695.         sflag = FALSE;
  696.         cflag = FALSE;
  697.         hflag = FALSE;
  698.         mflag = FALSE;
  699.         Mflag = FALSE;
  700.         fflag = FALSE;
  701.         pflag = FALSE;
  702.     }
  703.     if(strcmp(suffix, "c") == 0){
  704.         cflag = TRUE;
  705.         hflag = FALSE;
  706.         mflag = FALSE;
  707.         Mflag = FALSE;
  708.         sflag = FALSE;
  709.         fflag = FALSE;
  710.         xflag = FALSE;
  711.         pflag = FALSE;
  712.     }
  713.     if(strcmp(suffix, "h") == 0){
  714.         hflag = TRUE;
  715.         cflag = FALSE;
  716.         mflag = FALSE;
  717.         Mflag = FALSE;
  718.         sflag = FALSE;
  719.         fflag = FALSE;
  720.         xflag = FALSE;
  721.         pflag = FALSE;
  722.     }
  723.     if(strcmp(suffix, "f") == 0){
  724.         fflag = TRUE;
  725.         hflag = FALSE;
  726.         cflag = FALSE;
  727.         mflag = FALSE;
  728.         Mflag = FALSE;
  729.         sflag = FALSE;
  730.         xflag = FALSE;
  731.         pflag = FALSE;
  732.     }
  733.     if(strcmp(suffix, "p") == 0){
  734.         pflag = TRUE;
  735.         hflag = FALSE;
  736.         cflag = FALSE;
  737.         mflag = FALSE;
  738.         Mflag = FALSE;
  739.         sflag = FALSE;
  740.         xflag = FALSE;
  741.         fflag = FALSE;
  742.     }
  743.     if(isdigit(*suffix) != 0) {
  744.         Mflag = TRUE;
  745.         hflag = FALSE;
  746.         cflag = FALSE;
  747.         mflag = FALSE;
  748.         sflag = FALSE;
  749.         fflag = FALSE;
  750.         xflag = FALSE;
  751.         pflag = FALSE;
  752.     }
  753.     set_flags();
  754.     if(!qflag || debugon)
  755.         printf("Hmm.  This file looks like a %s file.\n", msg_name);
  756. }
  757.  
  758. /*
  759.  * set_flags - set & check flags
  760.  */
  761.  
  762. set_flags()
  763. {
  764.     if(cflag || hflag || mflag || Mflag || sflag || fflag || xflag) {
  765.         if(cflag) {
  766.             msg_name = m_stdc;
  767.             header = h_stdc;
  768.         }
  769.         if(hflag) {
  770.             msg_name = m_include;
  771.             header = h_include;
  772.         }
  773.         if(mflag) {
  774.             msg_name = m_make;
  775.             header = h_make;
  776.         }
  777.         if(Mflag) {
  778.             msg_name = m_manual;
  779.             header = h_manual;
  780.         }
  781.         if(sflag) {
  782.             msg_name = m_shell;
  783.             header = h_make;
  784.         }
  785.         if(fflag) {
  786.             msg_name = m_fortran;
  787.             header = h_fortran;
  788.         }
  789.         if(xflag) {
  790.             msg_name = m_tex;
  791.             header = h_tex;
  792.         }
  793.         if(pflag) {
  794.             msg_name = m_pascal;
  795.             header = h_pascal;
  796.         }
  797.     } else {
  798.         cflag = TRUE;
  799.         set_flags();
  800.     }
  801. }
  802.  
  803. /*
  804.  * copy from -> to
  805.  */
  806.  
  807. copy(from, to, mode)
  808. char *from;
  809. char *to;
  810. char *mode;
  811. {
  812.     FILE *fdfrom, *fdto, *fopen();
  813.     char tmp[LENGTH];
  814.     char s[LENGTH];
  815.  
  816.     if((fdfrom = fopen(from, "r")) == NULL) {
  817.         fatal("Cannot open %s for reading.",from);
  818.     }
  819.     if((fdto = fopen(to, mode)) == NULL) {
  820.         fatal("Cannot open %s for \"%s\".",to,mode);
  821.     }
  822.     while(fgets(s, sizeof(s), fdfrom) != NULL)
  823.         fputs(s, fdto);
  824.     fclose(fdfrom);
  825.     fclose(fdto);
  826. }
  827.  
  828. /*
  829.  * Run RCS's rcsprog on file with flags.
  830.  */
  831.  
  832. rcs(rcsprog, file, flags)
  833. char *rcsprog;
  834. char *file;
  835. char *flags;
  836. {
  837.     char buf[LENGTH];
  838.     char tmp[LENGTH];
  839.  
  840.     if(!checkfor("q", flags) && qflag)
  841.         flags = "q";
  842.     if(!flags || !*flags)
  843.         sprintf(buf, "%s %s", rcsprog, file);
  844.     else
  845.         sprintf(buf, "%s -%s %s", rcsprog, flags, file);
  846.     debug(sprintf(tmp,"Running ``%s''...\n", buf));
  847.     if(!qflag)
  848.         lineprint(sprintf(tmp, "Start of ``%s''", buf));
  849.     system(buf);
  850.     if(!qflag)
  851.         lineprint(sprintf(tmp, "End of ``%s''", buf));
  852. }
  853.  
  854. /*
  855.  * checkdir - make RCS directory if not present.
  856.  */
  857.  
  858. checkdir()
  859. {
  860.     if(access("RCS", 0) != 0){
  861.         if(!qflag || debugon)
  862.             printf("Cannot find \"RCS\" directory.  Creating...\n");
  863.         if(strcmp(rcsdir, "RCS") != 0) { 
  864.             if(symlink(rcsdir, "RCS") != 0)
  865.                 fatal("Symbolic link of %s to RCS failed.", 
  866.                     rcsdir);
  867.         } else {
  868.             if(mkdir(rcsdir, 0755) != 0)
  869.                 fatal("Cannot create \"%s\" directory.", 
  870.                     rcsdir);
  871.         }
  872.     }
  873. }
  874.  
  875. /*
  876.  * checkfor(x, str) -- check for x in str.  Return 1 (TRUE) if exists.
  877.  *            Otherwise 0 (FALSE).
  878.  */
  879.  
  880. checkfor(x, str)
  881. char     *x;
  882. char     *str;
  883. {
  884.     if (!str)
  885.         return(FALSE);
  886.     while(*str) {
  887.         if(strcmp(str, x) == 0)
  888.             return(TRUE);
  889.         *str++;
  890.     }
  891.     return(FALSE);
  892. }
  893.  
  894. /*
  895.  * lineprint - print msg in a nice line
  896.  */
  897.  
  898. lineprint(msg)
  899. char *msg;
  900. {
  901.     int len, left, right, x;
  902.  
  903.     len = strlen(msg);
  904.     right = (75-len)/2;
  905.     left = right;
  906.     for(x = 0; x < right; ++x)
  907.         putchar('-');
  908.     printf("[ %s ]", msg);
  909.     for(x = 0; x < left; ++x)
  910.         putchar('-');
  911.     putchar('\n');
  912. }
  913.  
  914. /*
  915.  * fatal - print error and then exit(1).
  916.  */
  917. fatal(format, str)
  918. char *format;
  919. {
  920.     static char namefmt[100];
  921.  
  922.     sprintf(namefmt, "%s: %s\n", progname, format);
  923.     _doprnt(namefmt, &str, stderr);
  924.     exit(1);
  925. }
  926.  
  927. /*
  928.  * zap str with NULL's
  929.  */
  930.  
  931. zap(str)
  932. char str[];
  933. {
  934.     int i, x;
  935.  
  936.     i = strlen(str);
  937.     for(x = 0; x <= i; )
  938.         str[x++] = NULL;
  939. }
  940.  
  941. /*
  942.  * get header names
  943.  */
  944.  
  945. get_temp()
  946. {
  947.     zap(tbuf);
  948.     if(mflag)
  949.         strcpy(tbuf, header_make);
  950.     if(Mflag)
  951.         strcpy(tbuf, header_man);
  952.     if(hflag)
  953.         strcpy(tbuf, header_h);
  954.     if(cflag)
  955.         strcpy(tbuf, header_c);
  956.     if(sflag)
  957.         strcpy(tbuf, header_sh);
  958.     if(fflag)
  959.         strcpy(tbuf, header_f);
  960.     if(xflag)
  961.         strcpy(tbuf, header_tex);
  962.     if(pflag)
  963.         strcpy(tbuf, header_p);
  964. }
  965.  
  966. usage()
  967. {
  968.     fprintf(stderr, "usage: %s ", progname);
  969.     fprintf(stderr, USAGE);
  970. }
  971. SHAR_EOF
  972. echo shar: extracting "'_.header.c'" '(605 characters)'
  973. if test -f '_.header.c'
  974. then
  975.     echo shar: over-writing existing file "'_.header.c'"
  976. fi
  977. cat << \SHAR_EOF > '_.header.c'
  978. #ifndef lint
  979. static char *RCSid = "$Header$";
  980. #endif
  981.  
  982. /*
  983.  *------------------------------------------------------------------
  984.  *
  985.  * $Source$
  986.  * $Revision$
  987.  * $Date$
  988.  * $State$
  989.  * $Author$
  990.  * $Locker$
  991.  *
  992.  *------------------------------------------------------------------
  993.  *
  994.  * Michael Cooper (mcooper@usc-oberon.arpa)
  995.  * University Computing Services,
  996.  * University of Southern California,
  997.  * Los Angeles, California,   90089-0251
  998.  * (213) 743-3469
  999.  *
  1000.  *------------------------------------------------------------------
  1001.  * $Log$
  1002.  *------------------------------------------------------------------
  1003.  */
  1004.  
  1005. SHAR_EOF
  1006. #    End of shell archive
  1007. exit 0
  1008.  
  1009.